/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * RegistroUnidad.java
 *
 * Created on 02-may-2012, 23:13:48
 */
package com.camachosanchez.gui;

import com.camachosanchez.bean.*;
import com.camachosanchez.controler.jdbc.ControlCambioNeumaticoJdbcControler;
import com.camachosanchez.controler.jdbc.TipoVehiculoJdbcControler;
import com.camachosanchez.controler.jdbc.VehiculosJdbcControler;
import com.camachosanchez.controler.jpa.DistribuidoresVehiculosJpaController;
import com.camachosanchez.controler.jpa.FlotillasJpaController;
import com.camachosanchez.controler.jpa.FormasPagoJpaController;
import com.camachosanchez.controler.jpa.MarcasVehiculoJpaController;
import com.camachosanchez.controler.jpa.NeumaticosJpaController;
import com.camachosanchez.controler.jpa.TiposCombustibleJpaController;
import com.camachosanchez.controler.jpa.VehiculosJpaController;
import com.camachosanchez.gui.textfield.MaxLengthTextDocument;
import com.camachosanchez.util.Constantes;
import com.camachosanchez.util.GUIUtil;
import com.camachosanchez.util.SQLUtil;
import java.awt.Point;
import java.awt.event.KeyEvent;
import java.util.Date;
import java.util.List;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JOptionPane;

/**
 *
 * @author Rolando
 */
public class EditorUnidad extends javax.swing.JDialog {

    private Vehiculos vehiculo;
    private BusquedaEquipo buscador;
    private int fila = 0;

    /**
     * Creates new form RegistroUnidad
     */
    public EditorUnidad(BusquedaEquipo buscador, java.awt.Frame parent, boolean modal, Vehiculos v, int fila) {
        initComponents();
        GUIUtil.addEscapeKey(this);
        dateFechaRegistro.setDate(new Date());
//        setModal(modal);
        MaxLengthTextDocument doc_placa = new MaxLengthTextDocument();
        MaxLengthTextDocument doc_serie = new MaxLengthTextDocument();
        MaxLengthTextDocument doc_motor = new MaxLengthTextDocument();
        MaxLengthTextDocument doc_factura = new MaxLengthTextDocument();
        MaxLengthTextDocument doc_codbarras = new MaxLengthTextDocument();
        MaxLengthTextDocument doc_inventario = new MaxLengthTextDocument();
        MaxLengthTextDocument doc_capacidad = new MaxLengthTextDocument();
        MaxLengthTextDocument doc_precio = new MaxLengthTextDocument();
        doc_placa.setMaxChars(10, Constantes.CADENAS);
        doc_serie.setMaxChars(20, Constantes.CADENAS);
        doc_motor.setMaxChars(20, Constantes.CADENAS);
        doc_factura.setMaxChars(20, Constantes.CADENAS);
        doc_codbarras.setMaxChars(6, Constantes.CADENAS);
        doc_inventario.setMaxChars(20, Constantes.ENTEROS);
        doc_capacidad.setMaxChars(20, Constantes.ENTEROS);
        doc_precio.setMaxChars(10, Constantes.DECIMALES);
        txtPlaca.setDocument(doc_placa);
        txtSerie.setDocument(doc_serie);
        txtNroMotor.setDocument(doc_motor);
        txtFactura.setDocument(doc_factura);
        txtCodigoBarras.setDocument(doc_codbarras);
        txtNroInventario.setDocument(doc_inventario);
        txtCapacidadTanque.setDocument(doc_capacidad);
        txtPrecio.setDocument(doc_precio);
        this.vehiculo = v;
        llenarListasDesplegables();
        if (vehiculo != null) {
            txtPlaca.setText(vehiculo.getPlaca());
            txtSerie.setText(vehiculo.getSerieChasis());
            txtNroMotor.setText(vehiculo.getNumeroMotor());
            txtFactura.setText(vehiculo.getNumFacturaCompra());
            txtCodigoBarras.setText(vehiculo.getCodBarras());
            dateFechaRegistro.setDate(vehiculo.getFechaRegistro());
            comboTiposVehiculos.setSelectedItem(vehiculo.getIdTipo());
            comboMarcasVehiculos.setSelectedItem(vehiculo.getIdMarca());
            comboTiposCombustible.setSelectedItem(vehiculo.getIdCombustible());
            txtCapacidadTanque.setText(vehiculo.getCapacidadTanque());
            txtNroInventario.setText(vehiculo.getNumeroInventario());
            dateFechaCompra.setDate(vehiculo.getFechaCompra());
            comboFlotillas.setSelectedItem(vehiculo.getIdFlotilla());
            txtCargaKg.setText("" + vehiculo.getMaximaCapacidadCargaPeso());
            txtCargaM3.setText("" + vehiculo.getMaximaCapacidadCargaVolumen());
            comboModeloChasis.setSelectedItem(vehiculo.getIdTipoEje());
            actualizarImagenModelo();
            comboDistribuidores.setSelectedItem(vehiculo.getIdDistribuidor());
            comboFormasPago.setSelectedItem(vehiculo.getIdFormaPago());
            txtPrecio.setText("" + vehiculo.getPrecioVehiculo());
            txpComentarios.setText(vehiculo.getComentarios());
            spnNumeroBaterias.setValue(vehiculo.getNroBaterias());
//            this.vehiculo = vehiculo;
            this.fila = fila;
            this.buscador = buscador;
        }
        dateFechaRegistro.setMaxSelectableDate(new Date());
        dateFechaCompra.setMaxSelectableDate(new Date());
        setModal(true);
        pack();
        setLocationRelativeTo(null);
    }

    private void llenarListasDesplegables() {
//        TiposVehiculoJpaController tipos_vehiculo_dao = new TiposVehiculoJpaController(null);
        TipoVehiculoJdbcControler tipos_vehiculo_dao = new TipoVehiculoJdbcControler();
        MarcasVehiculoJpaController marcas_vehiculo_dao = new MarcasVehiculoJpaController(null);
        TiposCombustibleJpaController tipos_combustible_dao = new TiposCombustibleJpaController(null);
        FlotillasJpaController flotillas_dao = new FlotillasJpaController(null);
//        TiposEjeJpaController ejes_dao = new TiposEjeJpaController(null);
        DistribuidoresVehiculosJpaController distribuidor_dao = new DistribuidoresVehiculosJpaController(null);
        FormasPagoJpaController formas_pago_dao = new FormasPagoJpaController(null);

//        List<TiposVehiculo> tipos_vehiculos = tipos_vehiculo_dao.findTiposVehiculoEntities();
        List<TiposVehiculo> tipos_vehiculos = tipos_vehiculo_dao.findAll();
        List<MarcasVehiculo> marcas_vehiculos = marcas_vehiculo_dao.findMarcasVehiculoEntities();
        List<TiposCombustible> tipos_combustible = tipos_combustible_dao.findTiposCombustibleEntities();
        List<Flotillas> flotillas = flotillas_dao.findFlotillasEntities();
//        List<TiposEje> ejes = ejes_dao.findTiposEjeEntities();
        List<DistribuidoresVehiculos> distribuidores = distribuidor_dao.findDistribuidoresVehiculosEntities();
        List<FormasPago> formas = formas_pago_dao.findFormasPagoEntities();

        tipos_combustible.add(0, null);
        comboTiposVehiculos.setModel(new DefaultComboBoxModel(tipos_vehiculos.toArray()));
//        comboTiposVehiculos.setModel(new DefaultComboBoxModel());
//        comboTiposVehiculos.addItem(vehiculo.getIdTipo());
        comboMarcasVehiculos.setModel(new DefaultComboBoxModel(marcas_vehiculos.toArray()));
        comboTiposCombustible.setModel(new DefaultComboBoxModel(tipos_combustible.toArray()));
        comboFlotillas.setModel(new DefaultComboBoxModel(flotillas.toArray()));

        TiposVehiculo tipoSeleccionado = (TiposVehiculo) comboTiposVehiculos.getSelectedItem();
        List<TiposEje> tiposEje = SQLUtil.getTiposEjesIgualesXTipoVehiculo(vehiculo.getIdTipoEje(), tipoSeleccionado);
//        comboModeloChasis.setModel(new DefaultComboBoxModel(tiposEje.toArray()));
//        comboModeloChasis.setModel(new DefaultComboBoxModel());
//        comboModeloChasis.addItem(vehiculo.getIdTipoEje());
        comboDistribuidores.setModel(new DefaultComboBoxModel(distribuidores.toArray()));
        comboFormasPago.setModel(new DefaultComboBoxModel(formas.toArray()));

//        List<TiposEje> ejes = tiposEje;
//        List<TiposEje> ejesActivos = new ArrayList<TiposEje>();
//        for(TiposEje item : ejes){
//            if(item.getActivo()){
//                ejesActivos.add(item);
//            }
//        }
        comboModeloChasis.setModel(new DefaultComboBoxModel(tiposEje.toArray()));

//        actualizarImagenModelo();
    }

    private void actualizarImagenModelo() {
        TiposVehiculo tp = (TiposVehiculo) comboTiposVehiculos.getSelectedItem();
        TiposEje eje_seleccionado = (TiposEje) comboModeloChasis.getSelectedItem();
        if (tp != null && eje_seleccionado != null) {
            if (tp.getNombre().toUpperCase().compareTo("SEMIREMOLQUE") == 0) {
                Point p = SQLUtil.numeroEjes(eje_seleccionado.getId());
                txtNroEjes.setText("" + p.x);
                txtNroLlantas.setText("" + p.y);
                if (p.x < 6) {
                    lblImagen.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/camachosanchez/recursos/" + p.x + "-eje.png")));
                } else {
                    lblImagen.setIcon(null);
                }
            } else if (tp.getNombre().toUpperCase().compareTo("REMOLCADOR") == 0) {
                Point p = SQLUtil.numeroEjes(eje_seleccionado.getId());
                txtNroEjes.setText("" + p.x);
                txtNroLlantas.setText("" + p.y);
                if (p.x > 1 && p.x < 4) {
                    lblImagen.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/camachosanchez/recursos/" + p.x + "-eje-cabezal.png")));
                } else {
                    lblImagen.setIcon(null);
                }
            } else if (tp.getNombre().toUpperCase().compareTo("FURGÓN") == 0) {
                Point p = SQLUtil.numeroEjes(eje_seleccionado.getId());
                txtNroEjes.setText("" + p.x);
                txtNroLlantas.setText("" + p.y);
                if (p.x > 1 && p.x < 5) {
                    lblImagen.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/camachosanchez/recursos/" + p.x + "-eje-bus.png")));
                } else {
                    lblImagen.setIcon(null);
                }
            }
        }
    }

    private void actualizarVehiculo() {
        String numero_placa = txtPlaca.getText().trim();
        String serie_chasis = txtSerie.getText().trim();
        String numero_motor = txtNroMotor.getText().trim();
        String numero_factura = txtFactura.getText().trim();
        String codigo_barras = txtCodigoBarras.getText().trim();
        Date fecha_registro = dateFechaRegistro.getDate();
        TiposVehiculo tipo_vehiculo = (TiposVehiculo) comboTiposVehiculos.getSelectedItem();
        MarcasVehiculo marca_vehiculo = (MarcasVehiculo) comboMarcasVehiculos.getSelectedItem();
        TiposCombustible combustible = (TiposCombustible) comboTiposCombustible.getSelectedItem();
        Flotillas flota = (Flotillas) comboFlotillas.getSelectedItem();
        if (marca_vehiculo == null) {
            JOptionPane.showMessageDialog(this, Constantes.MARCA_UNIDAD_REQUERIDO, Constantes.DATOS_INCOMPLETOS, JOptionPane.WARNING_MESSAGE);
            comboMarcasVehiculos.requestFocusInWindow();
            return;
        }
        if (flota == null) {
            JOptionPane.showMessageDialog(this, Constantes.RAZON_SOCIAL_REQUERIDO, Constantes.DATOS_INCOMPLETOS, JOptionPane.WARNING_MESSAGE);
            comboFlotillas.requestFocusInWindow();
            return;
        }
        double capacidad_tanque;
        try {
            capacidad_tanque = Double.parseDouble(txtCapacidadTanque.getText());
        } catch (NumberFormatException e) {
            JOptionPane.showMessageDialog(this, "El valor ingresado para la capacidad del tanque debe ser un número decimal.", "Datos incorrectos", JOptionPane.WARNING_MESSAGE);
            txtCapacidadTanque.requestFocusInWindow();
            return;
        }
        String numero_inventario = txtNroInventario.getText();
        Date fecha_compra = dateFechaCompra.getDate();
        float maxima_capacidad_carga_kg;
        try {
            maxima_capacidad_carga_kg = Float.parseFloat(txtCargaKg.getText());
        } catch (NumberFormatException e) {
            JOptionPane.showMessageDialog(this, "El valor ingresado para la capacidad de carga debe ser un número decimal.", "Datos incorrectos", JOptionPane.WARNING_MESSAGE);
            txtCargaKg.requestFocusInWindow();
            return;
        }
        float maxima_capacidad_carga_volumen;
        try {
            maxima_capacidad_carga_volumen = Float.parseFloat(txtCargaM3.getText());
        } catch (NumberFormatException e) {
            JOptionPane.showMessageDialog(this, "El valor ingresado para la capacidad de carga debe ser un número decimal.", "Datos incorrectos", JOptionPane.WARNING_MESSAGE);
            txtCargaM3.requestFocusInWindow();
            return;
        }
        TiposEje ejes;
        if (comboModeloChasis.getSelectedItem() != null) {
            ejes = (TiposEje) comboModeloChasis.getSelectedItem();
        } else {
            JOptionPane.showMessageDialog(this, "Seleccione un modelo para el vehículo. Si no existe uno, ingréselo desde el menú Principal.", "Datos incompletos", JOptionPane.WARNING_MESSAGE);
            comboModeloChasis.requestFocusInWindow();
            return;
        }

        DistribuidoresVehiculos dist = (DistribuidoresVehiculos) comboDistribuidores.getSelectedItem();
        FormasPago forma = (FormasPago) comboFormasPago.getSelectedItem();
        double precio;
        try {
            precio = Double.parseDouble(txtPrecio.getText());
        } catch (NumberFormatException e) {
            JOptionPane.showMessageDialog(this, "El valor ingresado para el precio del equipo debe ser un número decimal.", "Datos incorrectos", JOptionPane.WARNING_MESSAGE);
            txtPrecio.requestFocusInWindow();
            return;
        }
        String comentario = txpComentarios.getText();
        if (numero_placa == null || numero_placa.isEmpty() || numero_placa.length() > 10) {
            JOptionPane.showMessageDialog(this, "El número de placa debe tener una longitud máxima de 20 caracteres.", "Datos incorrectos", JOptionPane.WARNING_MESSAGE);
            txtPlaca.requestFocusInWindow();
            return;
        }
        if (serie_chasis.length() > 20) {
            JOptionPane.showMessageDialog(this, "El número de serie del chasis debe tener una longitud máxima de 20 caracteres.", "Datos incorrectos", JOptionPane.WARNING_MESSAGE);
            txtSerie.requestFocusInWindow();
            return;
        }
        if (numero_motor.length() > 20) {
            JOptionPane.showMessageDialog(this, "El número de serie del motor debe tener una longitud máxima de 20 caracteres.", "Datos incorrectos", JOptionPane.WARNING_MESSAGE);
            txtNroMotor.requestFocusInWindow();
            return;
        }
        if (numero_factura.length() > 20) {
            JOptionPane.showMessageDialog(this, "El número de factura debe tener una longitud máxima de 20 caracteres.", "Datos incorrectos", JOptionPane.WARNING_MESSAGE);
            txtFactura.requestFocusInWindow();
            return;
        }
        if (codigo_barras != null && !codigo_barras.isEmpty()) {
            char caracterInicial = codigo_barras.charAt(0);
            if (Character.isLetter(caracterInicial)) {
                String strNumero = codigo_barras.substring(1);
                try {
                    Integer numero = Integer.parseInt(strNumero);
                } catch (NumberFormatException e) {
                    JOptionPane.showMessageDialog(this, "El código de la unidad debe estar formado por una letra y un número.", "Datos incorrectos", JOptionPane.WARNING_MESSAGE);
                    txtCodigoBarras.requestFocusInWindow();
                    return;
                }
            } else {
                JOptionPane.showMessageDialog(this, "El código de la unidad debe estar formado por una letra y un número.", "Datos incorrectos", JOptionPane.WARNING_MESSAGE);
                txtCodigoBarras.requestFocusInWindow();
                return;
            }
        }
        if (codigo_barras.length() > 6) {
            JOptionPane.showMessageDialog(this, "El código de barras debe tener una longitud máxima de 30 caracteres.", "Datos incorrectos", JOptionPane.WARNING_MESSAGE);
            txtCodigoBarras.requestFocusInWindow();
            return;
        }
        if (numero_inventario.length() > 20) {
            JOptionPane.showMessageDialog(this, "El número de inventario debe tener una longitud máxima de 20 caracteres.", "Datos incorrectos", JOptionPane.WARNING_MESSAGE);
            txtNroInventario.requestFocusInWindow();
            return;
        }
        String numero_baterias = spnNumeroBaterias.getValue().toString();
        Short num_baterias = 0;
        try {
            num_baterias = Short.parseShort(numero_baterias);
        } catch (NumberFormatException e) {
            JOptionPane.showMessageDialog(this, "El valor ingresado para el número de baterías debe ser un número.", "Datos incorrectos", JOptionPane.WARNING_MESSAGE);
            spnNumeroBaterias.requestFocusInWindow();
            return;
        }
        if (num_baterias > 5) {
            JOptionPane.showMessageDialog(this, "El número de baterías debe ser como máximo 5.", "Datos incorrectos", JOptionPane.WARNING_MESSAGE);
            spnNumeroBaterias.requestFocusInWindow();
            return;
        }
        short maxBaterias = vehiculo.getNroMaxBaterias();
        if (maxBaterias != 0 && num_baterias > maxBaterias) {
            JOptionPane.showMessageDialog(this, "El número de baterías debe ser como mínimo " + maxBaterias, "Datos incorrectos", JOptionPane.WARNING_MESSAGE);
            spnNumeroBaterias.requestFocusInWindow();
            return;
        } else if (num_baterias != 0 && maxBaterias == 0) {
            int posMaxima = SQLUtil.findPosMaximaMontajeBaterias(vehiculo.getId());
            if (posMaxima > 0 && num_baterias < posMaxima) {
                JOptionPane.showMessageDialog(this, "El número de baterías debe ser como mínimo " + posMaxima, "Datos incorrectos", JOptionPane.WARNING_MESSAGE);
                spnNumeroBaterias.requestFocusInWindow();
                return;
            }
        }
//        Vehiculos vehiculo = new Vehiculos();
        vehiculo.setPlaca(numero_placa);
        vehiculo.setFechaRegistro(fecha_registro);
        vehiculo.setCapacidadTanque("" + capacidad_tanque);
        vehiculo.setSerieChasis(serie_chasis);
        vehiculo.setNumeroMotor(numero_motor);
        vehiculo.setNumeroInventario(numero_inventario);
        vehiculo.setFechaCompra(fecha_compra);
        vehiculo.setNumFacturaCompra(numero_factura);
        vehiculo.setPrecioVehiculo(precio);
        vehiculo.setMaximaCapacidadCargaPeso(maxima_capacidad_carga_kg);
        vehiculo.setMaximaCapacidadCargaVolumen(maxima_capacidad_carga_volumen);
        vehiculo.setCodBarras(codigo_barras);
        vehiculo.setComentarios(comentario);
        vehiculo.setEstado(true);
        vehiculo.setIdUsuario(Constantes.currentUser);
        vehiculo.setIdMarca(marca_vehiculo);
        vehiculo.setIdTipo(tipo_vehiculo);
        vehiculo.setIdDistribuidor(dist);
        vehiculo.setIdCombustible(combustible);
        vehiculo.setIdFormaPago(forma);
        vehiculo.setIdFlotilla(flota);
        vehiculo.setFechaInsercionActualizacion(new Date());
        vehiculo.setIdTipoEje(ejes);
        vehiculo.setNroBaterias(num_baterias);
        VehiculosJpaController dao = new VehiculosJpaController(null);
        try {
            dao.edit(vehiculo);
            //ACTUALIZAR LA INFORMACIÓN DE SUS NEUMÁTICOS EN CASO HAYA CAMBIADO LA PLACA
            //--------------------------------------------------------------------------
            ControlCambioNeumaticoJdbcControler daoJdbc = new ControlCambioNeumaticoJdbcControler();
            List<DetalleControlCambioNeumatico> detalles = daoJdbc.findUltimoDetalleControlCambio(vehiculo.getId());
            NeumaticosJpaController nc = new NeumaticosJpaController(null);
            for (DetalleControlCambioNeumatico detalle : detalles) {
                if (detalle.getTipo() == Constantes.MONTAJE || detalle.getTipo() == Constantes.SIN_MOVIMIENTO) {
                    Neumaticos temp = detalle.getIdNeumatico();
                    if (temp != null) {
                        Neumaticos tire = nc.findNeumaticos(temp.getId());
                        if (tire != null) {
                            tire.setInfMontaje((vehiculo.getCodBarras() != null ? vehiculo.getCodBarras() : "") + " : " + vehiculo.getPlaca() + " : " + detalle.getPosicion());
                            nc.edit(tire);
                        }
                    }
                }
            }
            //--------------------------------------------------------------------------
            JOptionPane.showMessageDialog(this, "Los datos del equipo han sido actualizados correctamente.", "Operación finalizada", JOptionPane.INFORMATION_MESSAGE);
//            buscador.actualizarFila(vehiculo, fila);
            buscador.llenarTabla();
            dispose();
        } catch (Exception e) {
            JOptionPane.showMessageDialog(Principal.getInstance(), e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
        }
//        dao.create(vehiculo);
//        JOptionPane.showMessageDialog(this, "El equipo ha sido guardado correctamente.", "Operación finalizada", JOptionPane.INFORMATION_MESSAGE);
//        dispose();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jToolBar1 = new javax.swing.JToolBar();
        jPanel20 = new javax.swing.JPanel();
        btnGuardar = new javax.swing.JButton();
        btnMontaje = new javax.swing.JButton();
        btnDarBaja = new javax.swing.JButton();
        btnEliminar = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        jPanel2 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        txtPlaca = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        txtCodigoBarras = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        txtSerie = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        txtNroMotor = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        txtFactura = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        dateFechaRegistro = new com.toedter.calendar.JDateChooser();
        jPanel5 = new javax.swing.JPanel();
        jPanel3 = new javax.swing.JPanel();
        jPanel6 = new javax.swing.JPanel();
        jLabel8 = new javax.swing.JLabel();
        jPanel11 = new javax.swing.JPanel();
        comboTiposVehiculos = new javax.swing.JComboBox();
        jPanel7 = new javax.swing.JPanel();
        jLabel9 = new javax.swing.JLabel();
        jPanel12 = new javax.swing.JPanel();
        comboMarcasVehiculos = new javax.swing.JComboBox();
        jPanel8 = new javax.swing.JPanel();
        jLabel10 = new javax.swing.JLabel();
        jPanel13 = new javax.swing.JPanel();
        comboTiposCombustible = new javax.swing.JComboBox();
        jPanel9 = new javax.swing.JPanel();
        jLabel11 = new javax.swing.JLabel();
        txtCapacidadTanque = new javax.swing.JTextField();
        jPanel4 = new javax.swing.JPanel();
        jPanel14 = new javax.swing.JPanel();
        jLabel14 = new javax.swing.JLabel();
        txtNroInventario = new javax.swing.JTextField();
        jPanel15 = new javax.swing.JPanel();
        jLabel15 = new javax.swing.JLabel();
        dateFechaCompra = new com.toedter.calendar.JDateChooser();
        jPanel16 = new javax.swing.JPanel();
        jLabel16 = new javax.swing.JLabel();
        jPanel17 = new javax.swing.JPanel();
        comboFlotillas = new javax.swing.JComboBox();
        jPanel10 = new javax.swing.JPanel();
        jLabel12 = new javax.swing.JLabel();
        txtCargaKg = new javax.swing.JTextField();
        jLabel13 = new javax.swing.JLabel();
        txtCargaM3 = new javax.swing.JTextField();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        jPanel18 = new javax.swing.JPanel();
        jLabel17 = new javax.swing.JLabel();
        comboModeloChasis = new javax.swing.JComboBox();
        jLabel18 = new javax.swing.JLabel();
        txtNroEjes = new javax.swing.JTextField();
        jLabel19 = new javax.swing.JLabel();
        txtNroLlantas = new javax.swing.JTextField();
        jPanel21 = new javax.swing.JPanel();
        lblImagen = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        spnNumeroBaterias = new javax.swing.JSpinner();
        jPanel19 = new javax.swing.JPanel();
        jLabel20 = new javax.swing.JLabel();
        comboDistribuidores = new javax.swing.JComboBox();
        jLabel22 = new javax.swing.JLabel();
        comboFormasPago = new javax.swing.JComboBox();
        jLabel23 = new javax.swing.JLabel();
        txtPrecio = new javax.swing.JTextField();
        jLabel24 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        txpComentarios = new javax.swing.JTextPane();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle(".:: Editor de Unidades ::.");
        setResizable(false);

        jToolBar1.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jToolBar1.setFloatable(false);
        jToolBar1.setRollover(true);
        jToolBar1.setOpaque(false);

        jPanel20.setBackground(new java.awt.Color(255, 255, 255));
        jPanel20.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT));

        btnGuardar.setBackground(new java.awt.Color(255, 204, 102));
        btnGuardar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/camachosanchez/recursos/24_save.png"))); // NOI18N
        btnGuardar.setToolTipText("Guardar");
        btnGuardar.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        btnGuardar.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        btnGuardar.setMaximumSize(new java.awt.Dimension(22, 22));
        btnGuardar.setMinimumSize(new java.awt.Dimension(22, 22));
        btnGuardar.setPreferredSize(new java.awt.Dimension(22, 22));
        btnGuardar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnGuardar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnGuardarActionPerformed(evt);
            }
        });
        jPanel20.add(btnGuardar);

        btnMontaje.setBackground(new java.awt.Color(255, 204, 102));
        btnMontaje.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/camachosanchez/recursos/24_historial.png"))); // NOI18N
        btnMontaje.setToolTipText("Historial de montajes");
        btnMontaje.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        btnMontaje.setFocusable(false);
        btnMontaje.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        btnMontaje.setMaximumSize(new java.awt.Dimension(22, 22));
        btnMontaje.setMinimumSize(new java.awt.Dimension(22, 22));
        btnMontaje.setPreferredSize(new java.awt.Dimension(22, 22));
        btnMontaje.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnMontaje.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnMontajeActionPerformed(evt);
            }
        });
        jPanel20.add(btnMontaje);

        btnDarBaja.setBackground(new java.awt.Color(255, 204, 102));
        btnDarBaja.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/camachosanchez/recursos/24_delete.png"))); // NOI18N
        btnDarBaja.setToolTipText("Dar de baja");
        btnDarBaja.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        btnDarBaja.setFocusable(false);
        btnDarBaja.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        btnDarBaja.setMaximumSize(new java.awt.Dimension(22, 22));
        btnDarBaja.setMinimumSize(new java.awt.Dimension(22, 22));
        btnDarBaja.setPreferredSize(new java.awt.Dimension(22, 22));
        btnDarBaja.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jPanel20.add(btnDarBaja);

        btnEliminar.setBackground(new java.awt.Color(255, 204, 102));
        btnEliminar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/camachosanchez/recursos/24_eliminar.png"))); // NOI18N
        btnEliminar.setToolTipText("Eliminar");
        btnEliminar.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        btnEliminar.setFocusable(false);
        btnEliminar.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        btnEliminar.setMaximumSize(new java.awt.Dimension(22, 22));
        btnEliminar.setMinimumSize(new java.awt.Dimension(22, 22));
        btnEliminar.setPreferredSize(new java.awt.Dimension(22, 22));
        btnEliminar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnEliminar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnEliminarActionPerformed(evt);
            }
        });
        jPanel20.add(btnEliminar);

        jToolBar1.add(jPanel20);

        getContentPane().add(jToolBar1, java.awt.BorderLayout.PAGE_START);

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Información Principal", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 12))); // NOI18N
        jPanel2.setMaximumSize(new java.awt.Dimension(32767, 64));
        jPanel2.setMinimumSize(new java.awt.Dimension(403, 64));
        jPanel2.setOpaque(false);
        jPanel2.setPreferredSize(new java.awt.Dimension(447, 64));
        jPanel2.setLayout(new java.awt.GridLayout(3, 4, 5, 5));

        jLabel2.setText("<html>Número de placa: <font color=\"red\">(*)</font> </html>");
        jPanel2.add(jLabel2);

        txtPlaca.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                txtPlacaKeyPressed(evt);
            }
        });
        jPanel2.add(txtPlaca);

        jLabel6.setText("Código de unidad:");
        jPanel2.add(jLabel6);

        txtCodigoBarras.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                txtCodigoBarrasKeyPressed(evt);
            }
        });
        jPanel2.add(txtCodigoBarras);

        jLabel3.setText("Serie de chasis:");
        jPanel2.add(jLabel3);

        txtSerie.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                txtSerieKeyPressed(evt);
            }
        });
        jPanel2.add(txtSerie);

        jLabel4.setText("Número de motor:");
        jPanel2.add(jLabel4);

        txtNroMotor.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                txtNroMotorKeyPressed(evt);
            }
        });
        jPanel2.add(txtNroMotor);

        jLabel5.setText("Número de factura:");
        jPanel2.add(jLabel5);

        txtFactura.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                txtFacturaKeyPressed(evt);
            }
        });
        jPanel2.add(txtFactura);

        jLabel7.setText("<html>Fecha de registro: <font color=\"red\">(*)</font> </html>");
        jPanel2.add(jLabel7);

        dateFechaRegistro.setDateFormatString("dd/MM/yyyy");
        dateFechaRegistro.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                dateFechaRegistroKeyPressed(evt);
            }
        });
        jPanel2.add(dateFechaRegistro);

        jPanel5.setOpaque(false);
        jPanel5.setLayout(new java.awt.GridLayout(1, 0));

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Información Técnica", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 12))); // NOI18N
        jPanel3.setOpaque(false);
        jPanel3.setLayout(new java.awt.GridLayout(4, 1, 5, 5));

        jPanel6.setOpaque(false);
        jPanel6.setLayout(new java.awt.GridLayout(1, 0));

        jLabel8.setText("Tipo de vehículo:");
        jPanel6.add(jLabel8);

        jPanel11.setOpaque(false);
        jPanel11.setLayout(new java.awt.BorderLayout(5, 0));

        comboTiposVehiculos.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        comboTiposVehiculos.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                comboTiposVehiculosItemStateChanged(evt);
            }
        });
        comboTiposVehiculos.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                comboTiposVehiculosActionPerformed(evt);
            }
        });
        comboTiposVehiculos.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                comboTiposVehiculosKeyPressed(evt);
            }
        });
        jPanel11.add(comboTiposVehiculos, java.awt.BorderLayout.CENTER);

        jPanel6.add(jPanel11);

        jPanel3.add(jPanel6);

        jPanel7.setOpaque(false);
        jPanel7.setLayout(new java.awt.GridLayout(1, 2));

        jLabel9.setText("<html>Marca de unidad: <font color=\"red\">(*)</font> </html>");
        jPanel7.add(jLabel9);

        jPanel12.setOpaque(false);
        jPanel12.setLayout(new java.awt.BorderLayout(5, 0));

        comboMarcasVehiculos.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        comboMarcasVehiculos.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                comboMarcasVehiculosKeyPressed(evt);
            }
        });
        jPanel12.add(comboMarcasVehiculos, java.awt.BorderLayout.CENTER);

        jPanel7.add(jPanel12);

        jPanel3.add(jPanel7);

        jPanel8.setOpaque(false);
        jPanel8.setLayout(new java.awt.GridLayout(1, 2));

        jLabel10.setText("Tipo de combustible:");
        jPanel8.add(jLabel10);

        jPanel13.setOpaque(false);
        jPanel13.setLayout(new java.awt.BorderLayout(5, 0));

        comboTiposCombustible.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        comboTiposCombustible.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                comboTiposCombustibleKeyPressed(evt);
            }
        });
        jPanel13.add(comboTiposCombustible, java.awt.BorderLayout.CENTER);

        jPanel8.add(jPanel13);

        jPanel3.add(jPanel8);

        jPanel9.setOpaque(false);
        jPanel9.setLayout(new java.awt.GridLayout(1, 2));

        jLabel11.setText("Capacidad del tanque (L):");
        jPanel9.add(jLabel11);

        txtCapacidadTanque.setText("0");
        txtCapacidadTanque.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                txtCapacidadTanqueKeyPressed(evt);
            }
        });
        jPanel9.add(txtCapacidadTanque);

        jPanel3.add(jPanel9);

        jPanel5.add(jPanel3);

        jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Información de Almacenamiento", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 12))); // NOI18N
        jPanel4.setOpaque(false);
        jPanel4.setLayout(new java.awt.GridLayout(4, 1, 5, 5));

        jPanel14.setOpaque(false);
        jPanel14.setLayout(new java.awt.GridLayout(1, 2));

        jLabel14.setText("Número de inventario:");
        jPanel14.add(jLabel14);

        txtNroInventario.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                txtNroInventarioKeyPressed(evt);
            }
        });
        jPanel14.add(txtNroInventario);

        jPanel4.add(jPanel14);

        jPanel15.setOpaque(false);
        jPanel15.setLayout(new java.awt.GridLayout(1, 2));

        jLabel15.setText("Fecha de compra:");
        jPanel15.add(jLabel15);

        dateFechaCompra.setDateFormatString("dd/MM/yyyy");
        jPanel15.add(dateFechaCompra);

        jPanel4.add(jPanel15);

        jPanel16.setOpaque(false);
        jPanel16.setLayout(new java.awt.GridLayout(1, 2));

        jLabel16.setText("<html>Razón Social: <font color=\"red\">(*)</font> </html>");
        jPanel16.add(jLabel16);

        jPanel17.setOpaque(false);
        jPanel17.setLayout(new java.awt.BorderLayout(5, 0));

        comboFlotillas.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        comboFlotillas.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                comboFlotillasKeyPressed(evt);
            }
        });
        jPanel17.add(comboFlotillas, java.awt.BorderLayout.CENTER);

        jPanel16.add(jPanel17);

        jPanel4.add(jPanel16);

        jPanel10.setOpaque(false);
        jPanel10.setLayout(new java.awt.GridLayout(1, 4, 4, 0));

        jLabel12.setText("Carga (kg):");
        jPanel10.add(jLabel12);

        txtCargaKg.setText("0");
        txtCargaKg.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                txtCargaKgKeyPressed(evt);
            }
        });
        jPanel10.add(txtCargaKg);

        jLabel13.setText("Carga (m³):");
        jPanel10.add(jLabel13);

        txtCargaM3.setText("0");
        txtCargaM3.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                txtCargaM3KeyPressed(evt);
            }
        });
        jPanel10.add(txtCargaM3);

        jPanel4.add(jPanel10);

        jPanel5.add(jPanel4);

        jTabbedPane1.setBackground(new java.awt.Color(188, 211, 226));

        jLabel17.setText("<html>Nombre del modelo: <font color=\"red\">(*)</font> </html>");

        comboModeloChasis.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        comboModeloChasis.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                comboModeloChasisItemStateChanged(evt);
            }
        });

        jLabel18.setText("Número de Ejes:");

        txtNroEjes.setEditable(false);

        jLabel19.setText("Número de llantas:");

        txtNroLlantas.setEditable(false);

        jPanel21.setBackground(new java.awt.Color(255, 255, 255));
        jPanel21.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        jPanel21.setLayout(new java.awt.BorderLayout());

        lblImagen.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jPanel21.add(lblImagen, java.awt.BorderLayout.CENTER);

        jLabel1.setText("Número de baterías:");

        spnNumeroBaterias.setModel(new javax.swing.SpinnerNumberModel(0, 0, 5, 1));

        javax.swing.GroupLayout jPanel18Layout = new javax.swing.GroupLayout(jPanel18);
        jPanel18.setLayout(jPanel18Layout);
        jPanel18Layout.setHorizontalGroup(
            jPanel18Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel18Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel18Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jLabel18, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jLabel17)
                    .addComponent(jLabel19, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel18Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(txtNroLlantas, javax.swing.GroupLayout.DEFAULT_SIZE, 126, Short.MAX_VALUE)
                    .addComponent(txtNroEjes, javax.swing.GroupLayout.DEFAULT_SIZE, 126, Short.MAX_VALUE)
                    .addComponent(comboModeloChasis, 0, 126, Short.MAX_VALUE)
                    .addComponent(spnNumeroBaterias, javax.swing.GroupLayout.DEFAULT_SIZE, 126, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel21, javax.swing.GroupLayout.PREFERRED_SIZE, 391, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        jPanel18Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jLabel17, jLabel18, jLabel19});

        jPanel18Layout.setVerticalGroup(
            jPanel18Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel18Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel18Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel21, javax.swing.GroupLayout.DEFAULT_SIZE, 98, Short.MAX_VALUE)
                    .addGroup(jPanel18Layout.createSequentialGroup()
                        .addGroup(jPanel18Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel17, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(comboModeloChasis, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel18Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel18)
                            .addComponent(txtNroEjes, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel18Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel19)
                            .addComponent(txtNroLlantas, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel18Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel1)
                            .addComponent(spnNumeroBaterias, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );

        jTabbedPane1.addTab("Sistema de Ejes", jPanel18);

        jLabel20.setText("Distribuidor:");

        comboDistribuidores.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        comboDistribuidores.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                comboDistribuidoresKeyPressed(evt);
            }
        });

        jLabel22.setText("Forma de pago:");

        comboFormasPago.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        comboFormasPago.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                comboFormasPagoKeyPressed(evt);
            }
        });

        jLabel23.setText("Precio ($):");

        txtPrecio.setText("0.0");
        txtPrecio.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                txtPrecioKeyPressed(evt);
            }
        });

        jLabel24.setText("Comentarios:");

        jScrollPane1.setViewportView(txpComentarios);

        javax.swing.GroupLayout jPanel19Layout = new javax.swing.GroupLayout(jPanel19);
        jPanel19.setLayout(jPanel19Layout);
        jPanel19Layout.setHorizontalGroup(
            jPanel19Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel19Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel19Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jLabel20, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jLabel24, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel19Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel19Layout.createSequentialGroup()
                        .addComponent(comboDistribuidores, javax.swing.GroupLayout.PREFERRED_SIZE, 234, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jLabel22, javax.swing.GroupLayout.PREFERRED_SIZE, 84, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(comboFormasPago, javax.swing.GroupLayout.PREFERRED_SIZE, 111, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jLabel23, javax.swing.GroupLayout.PREFERRED_SIZE, 59, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txtPrecio, javax.swing.GroupLayout.DEFAULT_SIZE, 55, Short.MAX_VALUE))
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 571, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel19Layout.setVerticalGroup(
            jPanel19Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel19Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel19Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel20)
                    .addComponent(comboDistribuidores, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(comboFormasPago, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel23)
                    .addComponent(txtPrecio, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel22, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel19Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel19Layout.createSequentialGroup()
                        .addComponent(jLabel24)
                        .addGap(50, 50, 50))
                    .addGroup(jPanel19Layout.createSequentialGroup()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 67, Short.MAX_VALUE)
                        .addContainerGap())))
        );

        jTabbedPane1.addTab("Distribuidor, Costos y Comentarios", jPanel19);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jPanel5, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 664, Short.MAX_VALUE)
                    .addComponent(jPanel2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 664, Short.MAX_VALUE)
                    .addComponent(jTabbedPane1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, 101, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, 128, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jTabbedPane1)
                .addContainerGap())
        );

        getContentPane().add(jPanel1, java.awt.BorderLayout.CENTER);

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void comboModeloChasisItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_comboModeloChasisItemStateChanged
// TODO add your handling code here:
//    actualizarImagenModelo();
}//GEN-LAST:event_comboModeloChasisItemStateChanged

private void comboTiposVehiculosItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_comboTiposVehiculosItemStateChanged
// TODO add your handling code here:
//    actualizarImagenModelo();
}//GEN-LAST:event_comboTiposVehiculosItemStateChanged

private void btnGuardarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnGuardarActionPerformed
// TODO add your handling code here:
//    if (!SQLUtil.existeBus(jTextField1.getText())) {
    actualizarVehiculo();
//    } else {
//        JOptionPane.showMessageDialog(this, "Ya existe un bus registrado con el número de placa indicado.", "Datos incorrectos", JOptionPane.INFORMATION_MESSAGE);
//        jTextField1.requestFocusInWindow();
//    }
}//GEN-LAST:event_btnGuardarActionPerformed

    private void txtPlacaKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtPlacaKeyPressed
        // TODO add your handling code here:
        if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
            txtCodigoBarras.requestFocusInWindow();
        }
    }//GEN-LAST:event_txtPlacaKeyPressed

    private void txtSerieKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtSerieKeyPressed
        // TODO add your handling code here:
        if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
            txtNroMotor.requestFocusInWindow();
        }
    }//GEN-LAST:event_txtSerieKeyPressed

    private void txtFacturaKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtFacturaKeyPressed
        // TODO add your handling code here:
        if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
            dateFechaRegistro.requestFocusInWindow();
        }
    }//GEN-LAST:event_txtFacturaKeyPressed

    private void txtCapacidadTanqueKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtCapacidadTanqueKeyPressed
        // TODO add your handling code here:
        if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
            txtNroInventario.requestFocusInWindow();
        }
    }//GEN-LAST:event_txtCapacidadTanqueKeyPressed

    private void txtCargaKgKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtCargaKgKeyPressed
        // TODO add your handling code here:
        if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
            txtCargaM3.requestFocusInWindow();
        }
    }//GEN-LAST:event_txtCargaKgKeyPressed

    private void txtNroMotorKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtNroMotorKeyPressed
        // TODO add your handling code here:
        if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
            txtFactura.requestFocusInWindow();
        }
    }//GEN-LAST:event_txtNroMotorKeyPressed

    private void btnMontajeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnMontajeActionPerformed
        // TODO add your handling code here:
        MontajeDesmontaje taller = new MontajeDesmontaje(vehiculo);
        taller.setSize(Principal.getInstance().getEscritorio().getSize());
        Principal.getInstance().getEscritorio().add(taller);
        this.dispose();
        taller.setVisible(true);
        taller.generarEsquemaMontaje();
    }//GEN-LAST:event_btnMontajeActionPerformed

    private void comboDistribuidoresKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_comboDistribuidoresKeyPressed
        // TODO add your handling code here:
        if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
            comboFormasPago.requestFocusInWindow();
        }
    }//GEN-LAST:event_comboDistribuidoresKeyPressed

    private void comboFormasPagoKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_comboFormasPagoKeyPressed
        // TODO add your handling code here:
        if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
            txtPrecio.requestFocusInWindow();
        }
    }//GEN-LAST:event_comboFormasPagoKeyPressed

    private void txtPrecioKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtPrecioKeyPressed
        // TODO add your handling code here:
        if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
            txpComentarios.requestFocusInWindow();
        }
    }//GEN-LAST:event_txtPrecioKeyPressed

    private void dateFechaRegistroKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_dateFechaRegistroKeyPressed
        // TODO add your handling code here:
        if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
            comboTiposVehiculos.requestFocusInWindow();
        }
    }//GEN-LAST:event_dateFechaRegistroKeyPressed

    private void comboTiposVehiculosKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_comboTiposVehiculosKeyPressed
        // TODO add your handling code here:
        if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
            comboMarcasVehiculos.requestFocusInWindow();
        }
    }//GEN-LAST:event_comboTiposVehiculosKeyPressed

    private void comboMarcasVehiculosKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_comboMarcasVehiculosKeyPressed
        // TODO add your handling code here:
        if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
            comboTiposCombustible.requestFocusInWindow();
        }
    }//GEN-LAST:event_comboMarcasVehiculosKeyPressed

    private void comboTiposCombustibleKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_comboTiposCombustibleKeyPressed
        // TODO add your handling code here:
        if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
            txtCapacidadTanque.requestFocusInWindow();
        }
    }//GEN-LAST:event_comboTiposCombustibleKeyPressed

    private void txtNroInventarioKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtNroInventarioKeyPressed
        // TODO add your handling code here:
        if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
            dateFechaCompra.requestFocusInWindow();
        }
    }//GEN-LAST:event_txtNroInventarioKeyPressed

    private void comboFlotillasKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_comboFlotillasKeyPressed
        // TODO add your handling code here:
        if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
            txtCargaKg.requestFocusInWindow();
        }
    }//GEN-LAST:event_comboFlotillasKeyPressed

    private void txtCargaM3KeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtCargaM3KeyPressed
        // TODO add your handling code here:
        if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
            comboDistribuidores.requestFocusInWindow();
        }
    }//GEN-LAST:event_txtCargaM3KeyPressed

    private void btnEliminarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnEliminarActionPerformed
        // TODO add your handling code here:
        if (JOptionPane.showConfirmDialog(this, "¿Está seguro que desea eliminar este vehículo?") == JOptionPane.YES_OPTION) {
            VehiculosJdbcControler daoJdbc = new VehiculosJdbcControler();
            byte estado = daoJdbc.eliminarVehiculo(this.vehiculo.getId());
            if (estado == 1) {
                JOptionPane.showMessageDialog(this, "El vehículo se encuentra relacionado con otros registros, no puede ser eliminado.", "Error en la eliminación", JOptionPane.ERROR_MESSAGE);
            } else {
                JOptionPane.showMessageDialog(this, "El vehículo se ha eliminado de forma segura.", "Operación finalizada", JOptionPane.INFORMATION_MESSAGE);
                buscador.borrarEquipo(fila);
                dispose();
            }
        }
    }//GEN-LAST:event_btnEliminarActionPerformed

    private void comboTiposVehiculosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comboTiposVehiculosActionPerformed
        // TODO add your handling code here:
        TiposVehiculo tipoSeleccionado = (TiposVehiculo) comboTiposVehiculos.getSelectedItem();
        List<TiposEje> tiposEje = SQLUtil.getTiposEjesIgualesXTipoVehiculo(vehiculo.getIdTipoEje(), tipoSeleccionado);
//        List<TiposEje> ejes = tiposEje;
//        List<TiposEje> ejesActivos = new ArrayList<TiposEje>();
//        for(TiposEje item : ejes){
//            if(item.getActivo()){
//                ejesActivos.add(item);
//            }
//        }
        if (!tiposEje.isEmpty()) {
            comboModeloChasis.setModel(new DefaultComboBoxModel(tiposEje.toArray()));
            actualizarImagenModelo();
        } else {
            txtNroEjes.setText("0");
            txtNroLlantas.setText("0");
            comboModeloChasis.setModel(new DefaultComboBoxModel());
            lblImagen.setIcon(null);
        }
    }//GEN-LAST:event_comboTiposVehiculosActionPerformed

private void txtCodigoBarrasKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtCodigoBarrasKeyPressed
// TODO add your handling code here:
    if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
        txtSerie.requestFocusInWindow();
    }
}//GEN-LAST:event_txtCodigoBarrasKeyPressed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnDarBaja;
    private javax.swing.JButton btnEliminar;
    private javax.swing.JButton btnGuardar;
    private javax.swing.JButton btnMontaje;
    private javax.swing.JComboBox comboDistribuidores;
    private javax.swing.JComboBox comboFlotillas;
    private javax.swing.JComboBox comboFormasPago;
    private javax.swing.JComboBox comboMarcasVehiculos;
    private javax.swing.JComboBox comboModeloChasis;
    private javax.swing.JComboBox comboTiposCombustible;
    private javax.swing.JComboBox comboTiposVehiculos;
    private com.toedter.calendar.JDateChooser dateFechaCompra;
    private com.toedter.calendar.JDateChooser dateFechaRegistro;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel20;
    private javax.swing.JLabel jLabel22;
    private javax.swing.JLabel jLabel23;
    private javax.swing.JLabel jLabel24;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel10;
    private javax.swing.JPanel jPanel11;
    private javax.swing.JPanel jPanel12;
    private javax.swing.JPanel jPanel13;
    private javax.swing.JPanel jPanel14;
    private javax.swing.JPanel jPanel15;
    private javax.swing.JPanel jPanel16;
    private javax.swing.JPanel jPanel17;
    private javax.swing.JPanel jPanel18;
    private javax.swing.JPanel jPanel19;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel20;
    private javax.swing.JPanel jPanel21;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JPanel jPanel7;
    private javax.swing.JPanel jPanel8;
    private javax.swing.JPanel jPanel9;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JToolBar jToolBar1;
    private javax.swing.JLabel lblImagen;
    private javax.swing.JSpinner spnNumeroBaterias;
    private javax.swing.JTextPane txpComentarios;
    private javax.swing.JTextField txtCapacidadTanque;
    private javax.swing.JTextField txtCargaKg;
    private javax.swing.JTextField txtCargaM3;
    private javax.swing.JTextField txtCodigoBarras;
    private javax.swing.JTextField txtFactura;
    private javax.swing.JTextField txtNroEjes;
    private javax.swing.JTextField txtNroInventario;
    private javax.swing.JTextField txtNroLlantas;
    private javax.swing.JTextField txtNroMotor;
    private javax.swing.JTextField txtPlaca;
    private javax.swing.JTextField txtPrecio;
    private javax.swing.JTextField txtSerie;
    // End of variables declaration//GEN-END:variables
}
